import { exec } from 'child_process';
process.on('message', async function (commond: string) {
    // console.log('CHILD                                                                                      got message:', commond);
    const startTime: number = (new Date()).valueOf();
    let error: any = "", buffer = Buffer.from([]);
    const result = await new Promise(reslove => exec(commond, { maxBuffer: 1024 ** 3, encoding: "buffer" }, (err, stdout, stderr) => {
        buffer = stdout;
        if (err) error = err.message;
        if (stderr) error = stderr.toString();
        const result = buffer.toString();
        const length: number = result.length;
        const usedTime: number = (new Date()).valueOf() - startTime;
        reslove({ usedTime, error, result, length, buffer, commond });
    }));
    process.send({ arg: result, commond });
});